package com.rock.platform.core;

import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
import com.rock.platform.util.ActionJsonResult;
import com.rock.platform.util.JpaDialectUtils;
import com.rock.platform.util.SessionUtils;

public class ActionExceptionInterceptor extends AbstractInterceptor {
	private static final long serialVersionUID = -8452368269941218327L;

	public String intercept(ActionInvocation invocation) throws Exception {
		String value = "";
		try {
			value = invocation.invoke();
		} catch (Exception ex) {
			setExceptionToValueStack(invocation,
					JpaDialectUtils.getException(ex));
			throw ex;
		}

		return value;
	}

	private void setExceptionToValueStack(ActionInvocation invocation,
			String errDesc) {
		SessionUtils.setAttribute("exceptionString",
				ActionJsonResult.getErrorResult(errDesc));
	}
}